#ifndef COMMON_BASE_FILE_H_
#define COMMON_BASE_FILE_H_

#include <list>
#include <string>
#include <vector>

class File {
 public:
  File();
  ~File();

 public:
  static void WriteBinaryToFile(
      const std::string& file_name, unsigned char* data, int length);
  static void AppendBinaryToFile(
      const std::string& file_name, unsigned char* data, int length);
  static bool ReadFileToString(
      const std::string& file_name, std::string* res);
  static bool ReadFileToVector(
      const std::string& file_name, std::vector<std::string>* vec);
  static bool ReadFileToVector(
      const std::string& file_name,
      std::vector<std::vector<std::string> >* res,
      const std::string& pattern = " ");

  static bool ReadFileToList(
      const std::string& file_name, std::list<std::string>* res);
  static bool ReadFileToList(
      const std::string& file_name,
      std::list<std::vector<std::string> >* res,
      const std::string& pattern = " ");

  // if line_break is true, std::endl will be written after data
  static bool AppendDataToFile(
      const std::string& file_name,
      const std::string& data,
      bool line_break = false);

  static bool Exist(const std::string& path);
  static bool CreateDirectory(const std::string& path);

  static std::string GetFileName(const std::string& path);

  static std::vector<std::string> SplitString(
      const std::string& str, const std::string& seperator);
  static std::string TrimString(
      const std::string& str);
};

#endif  // COMMON_BASE_FILE_H_

